package com.study.www.config;

import com.study.www.model.JobConfig;
import com.study.www.utils.TaskUtils;
import lombok.extern.slf4j.Slf4j;
import org.quartz.*;

import java.util.Date;

/**
 * @Description: : 禁止并发执行
 * @date :Create in  2018/2/26- 11:10
 * @Version: V1.0
 * @Modified By:
 **/
//禁止并发执行注解
@DisallowConcurrentExecution
@Slf4j
public class QuartzJobFactory extends AbstractQuartzJob {

    public static final String SCHEDULEJOBKEY="scheduleJob";
    //execute会根据cron的规则进行执行
    @Override
    protected void doExecute(JobExecutionContext jobExecutionContext, Object object) throws Exception {
        Trigger trigger=jobExecutionContext.getTrigger();
        JobConfig config = (JobConfig) jobExecutionContext.getMergedJobDataMap().get(SCHEDULEJOBKEY);
        //如果是手动立即执行一次，下次执行时间是null
        log.info(config.getJobName()+"-任务下次执行时间：{}",trigger.getFireTimeAfter(new Date()));
        TaskUtils.invokMethod(config);
    }

}
